package com.bbu.javaexam.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bbu.javaexam.domain.Student;
import org.apache.ibatis.annotations.*;

/**
 * @author Alex
 * @version 1.0.0
 * @ClassName StudentMapper.java
 * @Description TODO
 */
@Mapper
public interface StudentMapper extends BaseMapper<Student> {
    /**
     * @throws
     * @title 分页查询所有学生列表
     * @description
     * @author Alex
     */
    @Select("select * from student")
    IPage<Student> findAll(Page page);

    /**
     * @throws
     * @title 查询某个学生通过Id去查询
     * @description
     * @author Alex
     */
    @Select("select * from student where studentId = #{studentId}")
    Student findById(Integer studentId);

    /**
     * @throws
     * @title 删除学生通过ID
     * @description
     * @author Alex
     */
    @Delete("delete from student where studentId = #{studentId}")
    int deleteById(Integer studentId);

    /**
     * @throws
     * @title 传递一个对象更新学生数据
     * @description
     * @author Alex
     */
    @Update("update student set studentName = #{studentName},grade = #{grade},major = #{major},clazz = #{clazz}," +
            "institute = #{institute},tel = #{tel},email = #{email},pwd = #{pwd},cardId = #{cardId},sex = #{sex},role = #{role} " +
            "where studentId = #{studentId}")
    int update(Student student);

    /**
     * @throws
     * @title 更新学生密码
     * @description
     * @author Alex
     */
    @Update("update student set pwd = #{pwd} where studentId = #{studentId}")
    int updatePwd(Student student);

    /**
     * @throws
     * @title 增加一个学生
     * @description
     * @author Alex
     */
    @Options(useGeneratedKeys = true, keyProperty = "studentId")
    @Insert("insert into student(studentName,grade,major,clazz,institute,tel,email,pwd,cardId,sex,role) values " +
            "(#{studentName},#{grade},#{major},#{clazz},#{institute},#{tel},#{email},#{pwd},#{cardId},#{sex},#{role})")
    int add(Student student);
}
